package com.example.streamdemo.producer;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

/**
 * @Package: com.example.streamdemo.producer
 * @ClassName: MyMessageProducer
 * @Author: Think
 * @CreateTime: 2021/7/16 8:24
 * @Description:
 */
@Slf4j
@Component
@EnableBinding(Source.class)
public class MyMessageProducer {

    @Autowired
    private Source source;

    public void send(String message){
        log.info("生产者开始发送消息！");
        source.output().send(MessageBuilder.withPayload(message).build());
    }

}
